@isTest
private class TestCaseUploadController {
	
	/*Condition where everthing works perfect*/
    static testMethod void testPerfectUpload() {
    	
    	/****Creating test database****/
    	West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
    	Account testAccount = TestDatabaseCMS.createAccountForTesting();
    	Lead testLead = TestDatabaseCMS.createLeadForTesting();
    	system.debug('testPerfectUpload  testAccount.Account_Id__C: '+testAccount.Account_Id__C+'  testLead.Lead_Id__c:  '+testLead.Lead_Id__c+'  The lead ID : '+testLead.id);
    	Blob csvFile = Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n'+testAccount.Account_Id__C+',Academic Probation,Test Subject 1,Test Description 1,4\n'+testLead.Lead_Id__c+',Academic Probation,Test Subject 1,Test Description 1');
    	String csvName = 'CSVUpload.csv';
    	//Report testReport = new Report(name='West Case Upload Results', DeveloperName='West_Case_Upload_Results');
    	//insert testReport;
    	
    	/****Testing****/
        test.startTest();
        ConsoleHomeController_AC mainController = new ConsoleHomeController_AC();
        CaseUploadController newController = new CaseUploadController(mainController);
        newController = new CaseUploadController();
        newController.csvFileContent=csvFile;
        newController.csvFileName=csvName;
        newController.readFile();
        //newController.getReportUrl();
        
        test.stopTest();
    }
    
    /*Condition where mandatory field error is thrown*/
    static testMethod void testMandatoryFieldError() {
    	
    	/****Creating test database****/
    	West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
    	Account testAccount = TestDatabaseCMS.createAccountForTesting();
    	Lead testLead = TestDatabaseCMS.createLeadForTesting();
    	Blob csvFile = Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n'+testAccount.Account_Id__C+',,Test Subject 1,Test Description 1,4\n'+testLead.Lead_Id__c+',Academic Probation,Test Subject 1,Test Description 1,4');
    	String csvName = 'CSVUpload.csv';
    	
    	/****Testing****/
        test.startTest();
        CaseUploadController newController = new CaseUploadController();
        newController.csvFileContent=csvFile;
        newController.csvFileName=csvName;
        newController.readFile();
        
        test.stopTest();
    }
    
    /*Condition where Id is neither Account nor Lead ID*/
    static testMethod void testInvalidIdUpload() {
    	
    	/****Creating test database****/
    	West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
    	Account testAccount = TestDatabaseCMS.createAccountForTesting();
    	Lead testLead = TestDatabaseCMS.createLeadForTesting();
    	Blob csvFile = Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n003sdfsfasdfa,Academic Probation,Test Subject 1,Test Description 1,4\n'+testLead.Lead_Id__c+',Academic Probation,Test Subject 1,Test Description 1,4');
    	String csvName = 'CSVUpload.csv';
    	
    	/****Testing****/
        test.startTest();
        CaseUploadController newController = new CaseUploadController();
        newController.csvFileContent=csvFile;
        newController.csvFileName=csvName;
        newController.readFile();
        
        test.stopTest();
    }
    
    /*Condition where File not selected*/
    static testMethod void testNoFileUpload() {
    	
    	/****Creating test database****/
    	West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
    	Account testAccount = TestDatabaseCMS.createAccountForTesting();
    	Lead testLead = TestDatabaseCMS.createLeadForTesting();
    	Blob csvFile = Blob.valueof('');
    	String csvName = '';
    	
    	/****Testing****/
        test.startTest();
        CaseUploadController newController = new CaseUploadController();
        //newController.csvFileContent=null;
        //newController.csvFileName=csvName;
        newController.readFile();
        
        test.stopTest();
    }
    
    /*Condition where Case Name does not match*/
    static testMethod void testFaultyCaseNameUpload() {
    	
    	/****Creating test database****/
    	West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
    	Account testAccount = TestDatabaseCMS.createAccountForTesting();
    	Lead testLead = TestDatabaseCMS.createLeadForTesting();
    	Blob csvFile = Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n'+testAccount.Account_Id__C+',Academic Prtion,Test Subject 1,Test Description 1,4\n'+testLead.Lead_Id__c+',Academic Probation,Test Subject 1,Test Description 1,4');
    	String csvName = 'CSVUpload.csv';
    	
    	/****Testing****/
        test.startTest();
        CaseUploadController newController = new CaseUploadController();
        newController.csvFileContent=csvFile;
        newController.csvFileName=csvName;
        newController.readFile();
        
        test.stopTest();
    }
    
    /*Condition where insert does not work for record*/
    static testMethod void testNoMatchingID() {
    	
    	/****Creating test database****/
    	West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
    	Account testAccount = TestDatabaseCMS.createAccountForTesting();
    	Lead testLead = TestDatabaseCMS.createLeadForTesting();
    	Blob csvFile = Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n001asdfasdfasdf,Academic Probation,Test Subject 1,Test Description 1,4\n'+testLead.Lead_Id__c+',Academic Probation,Test Subject 1,Test Description 1,4');
    	String csvName = 'CSVUpload.csv';
    	
    	/****Testing****/
        test.startTest();
        CaseUploadController newController = new CaseUploadController();
        newController.csvFileContent=csvFile;
        newController.csvFileName=csvName;
        newController.readFile();
        newController.getUploadResults();
        newController.activateUpload();
        newController.deactivateUpload();
        newController.closeResults();
        
        test.stopTest();
    }
    
    
   
    
    
}